package cn.ming.leo.resource;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import cn.ming.leo.bean.SystemInfo;
import cn.ming.leo.utils.FileUtil;
import cn.ming.leo.utils.TimeFormat;

@RestController
@RequestMapping("/common")
public class CommonResource {

	@RequestMapping(value = "/uploadimg", method = RequestMethod.POST)
	public @ResponseBody String uploadImg(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
//		String fileName = file.getOriginalFilename();
		String filePath = SystemInfo.find.byId("1").getValue();
		try {
			FileUtil.uploadFile(file.getBytes(), filePath, TimeFormat.timeNo());
		} catch (Exception e) {
		}
		// 返回json
		return "uploadimg success";
	}

}
